﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeBase
{
    public class SortMethod
    {
        //<T> where T : struct

        /// <summary>
        /// 快速排序
        /// </summary>
        /// <param name="array"></param>
        /// <param name="low"></param>
        /// <param name="high"></param>
        public static int[] QuickSort(int[] array, int low, int high)
        {
            var nonius = low;
            var j = high - 1;
            var flag = array[low];
            if ((high - low) > 1)
            {
                while (nonius < j)
                {
                    for (; nonius < j; j--)
                    {
                        if (array[j] < flag)
                        {
                            array[nonius++] = array[j];
                            break;
                        };
                    }
                    for (; nonius < j; nonius++)
                    {
                        if (array[nonius] > flag)
                        {
                            array[j--] = array[nonius];
                            break;
                        }
                    }
                }
                array[nonius] = flag;
                QuickSort(array, 0, nonius);
                QuickSort(array, nonius + 1, high);
            }
            return array;

        }


    }
}
